<?php
//全局公共函数

//输入时间戳，返回格式化的时间
function d($date)
{
	$d = date('Y-m-d', $date);
	list($year, $month, $day) = explode('-', $d);
	return $year . '年' . $month . '月' . $day . '日';
}

//根据输入的大小转换
function human_size_read($size)
{
	$danwei  = array('B', 'KB', 'MB', 'GB');
	$last = end($danwei);
	foreach($danwei as $val)
	{
		if($size <1024)
		{
			break;
		}
		if($val != $last)
		{
			$size /= 1024;
		}
	}
	if($val == $danwei[0])
	{
		return sprintf('%d %s', $size, $val);
	}
	else
	{
		return  sprintf('%0.2f %s', $size, $val);
	}
}
//截取中文字符串函数
function str($content,$start,$size) //内容,起始位置 长度
{			
	$length = $size + $start;
	for($i = 0; $i < $length; $i++)
	{
		$ascii = ord(substr($content,$i,1));	//获取首字节ascii值
		if($ascii >= 224){						//utf8编码,读取3个字节
			$tmp .= substr($content,$i,3);	
			$i+=2;
		}
		else if($ascii >=192)					//gbk编码	
		{			
			$tmp .= substr($content,$i,2);
			$i++;
		}
		else
		{
			$tmp .= substr($content,$i,1);
		}
	}
	return $tmp;
}
//绝对路径转换成相对路径
$copyright = '<div class="footer">Powered by <a href="mailto:yangzhiguo0903@163.com" style="color:#81AB37;">yangzhiguo</a>  © ' . date('Y', time()) . ' <font color="#FF8700">YZG Inc.</font></div>';
?>